package com.mango.ch08;

import java.io.IOException;
import java.net.URISyntaxException;

import com.mango.HDFSTools.HDFS_HA_API;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import com.mango.HDFSTools.HDFSAPI;

/**
 * 查找共同好友
 *
 * @author Mango
 */
public class ComFriendsJob {

    static Path inputPath = new Path("/ComFriendsJob/input");// input
    static Path outPath = new Path("/ComFriendsJob/output"); // output

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        // 创建输入文件夹
        HDFS_HA_API hdfs = new HDFS_HA_API();
        hdfs.checkInputPath(inputPath);
        hdfs.checkOutputPath(outPath);
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "ComFriendsJob");
        job.setJarByClass(ComFriendsJob.class);
        job.setNumReduceTasks(2);

        job.setMapperClass(ComFriendsMapper.class);
        job.setReducerClass(ComFriendsReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Text.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        FileOutputFormat.setOutputPath(job, outPath);
        FileInputFormat.setInputPaths(job, inputPath);
        boolean status = job.waitForCompletion(true);
        System.exit(status ? 0 : 1);
    }

}
